<template>
    <div>
        <h1>房型显示</h1>
        姓名<input type="text" v-model="info.names">
        面积<input type="text" v-model="info.min">-<input type="text" v-model="info.max">
        <input type="button" value="查询" @click="getlist">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>发布状态</td>
                    <td>上架状态</td>
                    <td>图片</td>
                    <td>创建时间</td>
                    <td>面积</td>
                    <td>操作</td>
                </tr>
                <tr v-for="itme in data.list":key="itme.Id">
                    <td>{{ itme.Name }}</td>
                    <td>{{ itme.FXZT }}</td>
                    <td>{{ itme.SJZT }}</td>
                    <td><img :src="itme.Img" width="100" height="100" ></td>
                    <td>{{ itme.CountTime }}</td>
                    <td>{{ itme.Mianji }}</td>
                    <td><input type="button" value="删除" @click="del(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)"></td>
                </tr>
            </tbody>
        </table>
        <div>
            <span>共 {{ data.totalcount }} 条</span>
        <span>每页 {{ info.pagesize }} 条</span>
        <span>共 {{ info.pageindex }}/{{ data.totalpage }} 页</span>
        <input type="button" value="首页" @click="gopage(1)">
        <input type="button" value="上一页" @click="gopage(info.pageindex-1)">
        <span v-for=" item in data.totalpage"@click="gopage(item)">
            {{ item }}
        </span>
        <input type="button" value="下一页" @click="gopage(info.pageindex+1)">
        <input type="button" value="尾页" @click="gopage(data.totalpage)">
        <input type="number"  v-model="info.pageindex">
        <input type="button" value="跳转" @click="gopage(info.pageindex)">
        </div>
    
    </div>
</template>

<script setup lang="ts">
import{ref, reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
  names: '',
  min:'',
  max:'',
  pageindex:1,
  pagesize:2
 
})
let data:any=reactive({
    list:[],
    totalcount:0,
    totalpage:0
})
onMounted(()=>{
    getlist();
})
const xg=(id:any)=>{
    router.push({
       path: '/fxUpdate',
        query:{id:id}
    }
)}

//----------------------删除-------------------
const del=(id:any)=>{
    axios({
        url:'/api/FX/del',
        method:'delete',
        params:{id:id}
    })
    .then((res)=>{
        console.log(res);

    if(res.data>0)
    {
        alert('删除成功')
        getlist();
        return;
    }
    else{
        alert('删除失败')
        return;
    }

    })
    .catch((err)=>{
        console.log(err);
        
    })
}
//----------------------显示-------------------
const getlist=()=>{
    axios({
        url:'/api/FX/GetAll',
        method:'get',
        params:info
    })
    .then((res)=>{
        console.log(res);
        Object.assign(data,res.data)
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
//----------------------分页---------------------
const show=()=>{
    info.pageindex=1;
    getlist()
}
const gopage=(num:any)=>{
    if(num<1)
    {
        info.pageindex=1;
        return;
    }
    if(num>data.totalpage)
    {
        info.pageindex=data.totalpage;
        return;
    }
    info.pageindex=num;
    getlist();
}

</script>

<style scoped>
span{
    margin: 10px;
}
</style>